******
*This is the code to replicate the models in Singh, Shane P. 2011. "How Compelling Is Compulsory Voting? A Multilevel Analysis of Turnout." Political Behavior 33 (1): 95-111.
*http://link.springer.com/article/10.1007%2Fs11109-010-9107-z
******

*Model 1;
use "/Users/singh/Google Drive/PLS/Research/Compulsory Voting/Turnout and Comp Rules/Singh, PB 2011 replication, aggregate.dta" 
reg turnout  severity gdppercapPPP  mdmhlog parliamentary if compulsory == 1 , vce(robust)


use "/Users/singh/Google Drive/PLS/Research/Compulsory Voting/Turnout and Comp Rules/Singh, PB 2011 replication.dta" , clear

*Model 2;
logit voted age female educ income efficacycont distance  gdppercapPPP  freedom  popdense mdmhlog parliamentary eneplog bicameral pperleg exeelec vicmarg  severity //*first restrict sample to observations used in the fuller models
logit voted  severity gdppercapPPP  mdmhlog parliamentary if compulsory == 1 & e(sample), vce(robust)


*Model 3;
#delimit;
xtmelogit voted age female educ income efficacycont distance  gdppercapPPP  freedom  popdense 
mdmhlog parliamentary eneplog bicameral pperleg exeelec vicmarg 
compulsory ||cntryyearnum: age female educ income efficacycont distance, laplace;


*Model 4;
#delimit;
xtmelogit voted age female educ income efficacycont distance  gdppercapPPP  freedom  popdense 
mdmhlog parliamentary eneplog bicameral pperleg exeelec vicmarg 
sanctions enforcement ||cntryyearnum: age female educ income efficacycont distance, laplace;


*Model 5;
#delimit;
xtmelogit voted age female educ income efficacycont distance  gdppercapPPP  freedom  popdense 
mdmhlog parliamentary eneplog bicameral pperleg exeelec vicmarg  
severity ||cntryyearnum: age female educ income efficacycont distance, laplace;



*Assign weights for appendix models
gen weight = 1 if voted ~=.

replace weight =	0.651508526	if cntryyear == "ALB_2005" & voted == 1
replace weight =	0.83367017	if cntryyear == "AUS_1996" & voted == 1
replace weight =	0.84176116	if cntryyear == "AUS_2004" & voted == 1
replace weight =	0.926400178	if cntryyear == "BELF1999" & voted == 1
replace weight =	0.839308069	if cntryyear == "BRA_2002" & voted == 1
replace weight =	0.848757606	if cntryyear == "BGR_2001" & voted == 1
replace weight =	0.729246488	if cntryyear == "CAN_1997" & voted == 1
replace weight =	0.609030837	if cntryyear == "CAN_2004" & voted == 1
replace weight =	0.864300131	if cntryyear == "CHL_1999" & voted == 1
replace weight =	0.678806219	if cntryyear == "CHL_2005" & voted == 1
replace weight =	0.879120879	if cntryyear == "CZE_1996" & voted == 1
replace weight =	0.798808557	if cntryyear == "CZE_2002" & voted == 1
replace weight =	0.893548387	if cntryyear == "DNK_1998" & voted == 1
replace weight =	0.878216481	if cntryyear == "DNK_2001" & voted == 1
replace weight =	0.868270901	if cntryyear == "FIN_2003" & voted == 1
replace weight =	0.737963196	if cntryyear == "FRA_2002" & voted == 1
replace weight =	0.903527718	if cntryyear == "DEU_1998" & voted == 1
replace weight =	0.7923674	if cntryyear == "DEU_2002" & voted == 1
replace weight =	0.735352467	if cntryyear == "HKG_2004" & voted == 1
replace weight =	0.877453896	if cntryyear == "HUN_1998" & voted == 1
replace weight =	0.674972783	if cntryyear == "HUN_2002" & voted == 1
replace weight =	0.928125	if cntryyear == "ISL_2003" & voted == 1
replace weight =	0.785186921	if cntryyear == "IRL_2002" & voted == 1
replace weight =	0.93097384	if cntryyear == "ISR_1996" & voted == 1
replace weight =	0.853234668	if cntryyear == "ISR_2003" & voted == 1
replace weight =	1.010212871	if cntryyear == "ITA_2006" & voted == 1
replace weight =	0.948407969	if cntryyear == "KOR_2000" & voted == 1
replace weight =	0.753164557	if cntryyear == "KOR_2004" & voted == 1
replace weight =	0.750448338	if cntryyear == "MEX_1997" & voted == 1
replace weight =	0.570554735	if cntryyear == "MEX_2000" & voted == 1
replace weight =	0.603616134	if cntryyear == "MEX_2003" & voted == 1
replace weight =	0.780102381	if cntryyear == "NLD_1998" & voted == 1
replace weight =	0.862875559	if cntryyear == "NZL_1996" & voted == 1
replace weight =	0.865671642	if cntryyear == "NZL_2002" & voted == 1
replace weight =	0.911505493 if cntryyear == "NOR_2001" & voted == 1
replace weight =	0.883502324	if cntryyear == "PER_2006" & voted == 1
replace weight =	0.883417813	if cntryyear == "POL_1997" & voted == 1
replace weight =	0.819982773	if cntryyear == "POL_2001" & voted == 1
replace weight =	0.899318301	if cntryyear == "PRT_2002" & voted == 1
replace weight =	0.85064536	if cntryyear == "PRT_2005" & voted == 1
replace weight =	0.953891193	if cntryyear == "ROU_1996" & voted == 1
replace weight =	0.750186614	if cntryyear == "ROU_2004" & voted == 1
replace weight =	0.789371856	if cntryyear == "RUS_1999" & voted == 1
replace weight =	0.789340102	if cntryyear == "RUS_2004" & voted == 1
replace weight =	0.998812508	if cntryyear == "SVN_1996" & voted == 1
replace weight =	0.789915966	if cntryyear == "SVN_2004" & voted == 1
replace weight =	1.032539073	if cntryyear == "ESP_1996" & voted == 1
replace weight =	0.894318054	if cntryyear == "ESP_2004" & voted == 1
replace weight =	0.893617021	if cntryyear == "SWE_1998" & voted == 1
replace weight =	0.882352941	if cntryyear == "SWE_2002" & voted == 1
replace weight =	0.5933356	if cntryyear == "CHE_1999" & voted == 1
replace weight =	0.504326663	if cntryyear == "CHE_2003" & voted == 1
replace weight =	0.934119961	if cntryyear == "TWN_1996" & voted == 1
replace weight =	0.803008248	if cntryyear == "TWN_2001" & voted == 1
replace weight =	0.72501096	if cntryyear == "TWN_2004" & voted == 1
replace weight =	0.986956522	if cntryyear == "UKR_1998" & voted == 1
replace weight =	0.849553189	if cntryyear == "GBR_1997" & voted == 1
replace weight =	0.808711333	if cntryyear == "GBR_2005" & voted == 1
replace weight =	0.637326274	if cntryyear == "USA_1996" & voted == 1
replace weight =	0.733571065	if cntryyear == "USA_2004" & voted == 1

		
replace weight =	4.741784038	if cntryyear ==	"ALB_2005" & voted == 0
replace weight =	16.82692308	if cntryyear ==	"AUS_1996" & voted == 0
replace weight =	8.341232227	if cntryyear ==	"AUS_2004" & voted == 0
replace weight =	1.648675172	if cntryyear ==	"BELF1999" & voted == 0
replace weight =	2.164056059	if cntryyear ==	"BRA_2002" & voted == 0
replace weight =	1.564867424	if cntryyear ==	"BGR_2001" & voted == 0
replace weight =	1.976958525	if cntryyear ==	"CAN_1997" & voted == 0
replace weight =	4.858695652	if cntryyear ==	"CAN_2004" & voted == 0
replace weight =	1.724793912	if cntryyear ==	"CHL_1999" & voted == 0
replace weight =	8.381294964	if cntryyear ==	"CHL_2005" & voted == 0
replace weight =	1.909633419	if cntryyear ==	"CZE_1996" & voted == 0
replace weight =	1.568477429	if cntryyear ==	"CZE_2002" & voted == 0
replace weight =	2.414285714	if cntryyear ==	"DNK_1998" & voted == 0
replace weight =	3.91521197	if cntryyear ==	"DNK_2001" & voted == 0
replace weight =	1.547987616	if cntryyear ==	"FIN_2003" & voted == 0
replace weight =	2.006292352	if cntryyear ==	"FRA_2002" & voted == 0
replace weight =	1.482593037	if cntryyear ==	"DEU_1998" & voted == 0
replace weight =	3.660220994	if cntryyear ==	"DEU_2002" & voted == 0
replace weight =	1.820418204	if cntryyear ==	"HKG_2004" & voted == 0
replace weight =	1.251526252	if cntryyear ==	"HUN_1998" & voted == 0
replace weight =	2.550490479	if cntryyear ==	"HUN_2002" & voted == 0
replace weight =	2.725	if cntryyear ==	"ISL_2003" & voted == 0
replace weight =	2.249488753	if cntryyear ==	"IRL_2002" & voted == 0
replace weight =	1.696230599	if cntryyear ==	"ISR_1996" & voted == 0
replace weight =	2.210915819	if cntryyear ==	"ISR_2003" & voted == 0
replace weight =	0.955686065	if cntryyear ==	"ITA_2006" & voted == 0
replace weight =	1.073418948	if cntryyear ==	"KOR_2000" & voted == 0
replace weight =	1.928571429	if cntryyear ==	"KOR_2004" & voted == 0
replace weight =	1.657579062	if cntryyear ==	"MEX_1997" & voted == 0
replace weight =	8.861003861	if cntryyear ==	"MEX_2000" & voted == 0
replace weight =	2.014234875	if cntryyear ==	"MEX_2003" & voted == 0
replace weight =	2.948717949	if cntryyear ==	"NLD_1998" & voted == 0
replace weight =	4.461942257	if cntryyear ==	"NZL_1996" & voted == 0
replace weight =	1.692307692	if cntryyear ==	"NZL_2002" & voted == 0
replace weight =	1.426907397	if cntryyear ==	"NOR_2001" & voted == 0
replace weight =	3.073308271	if cntryyear ==	"PER_2006" & voted == 0
replace weight =	1.143878463	if cntryyear ==	"POL_1997" & voted == 0
replace weight =	1.249106079	if cntryyear ==	"POL_2001" & voted == 0
replace weight =	1.323777403	if cntryyear ==	"PRT_2002" & voted == 0
replace weight =	1.651474531	if cntryyear ==	"PRT_2005" & voted == 0
replace weight =	1.209766926	if cntryyear ==	"ROU_1996" & voted == 0
replace weight =	2.023445464	if cntryyear ==	"ROU_2004" & voted == 0
replace weight =	1.726746773	if cntryyear ==	"RUS_1999" & voted == 0
replace weight =	1.783018868	if cntryyear ==	"RUS_2004" & voted == 0
replace weight =	1.003717472	if cntryyear ==	"SVN_1996" & voted == 0
replace weight =	1.717439294	if cntryyear ==	"SVN_2004" & voted == 0
replace weight =	0.884229717	if cntryyear ==	"ESP_1996" & voted == 0
replace weight =	1.875580316	if cntryyear ==	"ESP_2004" & voted == 0
replace weight =	1.708812261	if cntryyear ==	"SWE_1998" & voted == 0
replace weight =	1.896551724	if cntryyear ==	"SWE_2002" & voted == 0
replace weight =	1.580864497	if cntryyear ==	"CHE_1999" & voted == 0
replace weight =	2.407834101	if cntryyear ==	"CHE_2003" & voted == 0
replace weight =	1.287553648	if cntryyear ==	"TWN_1996" & voted == 0
replace weight =	1.924829157	if cntryyear ==	"TWN_2001" & voted == 0
replace weight =	3.864155251	if cntryyear ==	"TWN_2004" & voted == 0
replace weight =	1.029032258	if cntryyear ==	"UKR_1998" & voted == 0
replace weight =	1.671217914	if cntryyear ==	"GBR_1997" & voted == 0
replace weight =	1.49408814	if cntryyear ==	"GBR_2005" & voted == 0
replace weight =	2.120654397	if cntryyear ==	"USA_1996" & voted == 0
replace weight =	1.973929236	if cntryyear ==	"USA_2004" & voted == 0
						
						
svyset _n [pweight=weight], strata(cntryyearnum)


*Model A1;
#delimit;
svy: logit voted age female educ income efficacycont distance  gdppercapPPP  freedom  
popdense mdmhlog parliamentary eneplog bicameral pperleg exeelec vicmarg compulsory;


*Model A2;
#delimit;
svy: logit voted age female educ income efficacycont distance  gdppercapPPP  freedom  
popdense mdmhlog parliamentary eneplog bicameral pperleg exeelec vicmarg sanctions enforcement;


*Model A3;
#delimit;
svy: logit voted age female educ income efficacycont distance  gdppercapPPP  freedom  
popdense mdmhlog parliamentary eneplog bicameral pperleg exeelec vicmarg  severity;
